<!DOCTYPE html>
<html xmlns:th="http://www.thymeleaf.org"
      xmlns:shiro="http://www.pollix.at/thymeleaf/shiro">
<head th:include="include :: header"></head>
<body class="hold-transition skin-blue sidebar-mini">
<section class="content-header">
    <h1>发明专利信息维护</h1>
</section>
<section class="content">
    <div class="row">
        <div class="col-xs-12">
            <div class="box">
                <div class="box-header">
                    <form id="queryForm" onsubmit="return false;">
                        <div class="row">
                            <div class="form-inline">
                                <div class="form-group">
                                    <label for="query-proCode">专利名称</label>
                                    <input id="query-proCode" type="text" name="name" class="form-control"
                                           placeholder="请输入专利名称">
                                </div>
                                <div class="form-group">
                                    <label for="query-proName">发明人</label>
                                    <input id="query-proName" type="text" name="inventor" class="form-control"
                                           placeholder="请输入发明人">
                                </div>
                                <div class="form-group">
                                    <label for="query-typeName">申请类型</label>
                                    <select id="query-typeName" class="form-control" name="typeName">
                                        <option value="" selected="selected">请选择</option>
                                        <option value="发明">发明</option>
                                        <option value="实用新型">实用新型</option>
                                        <option value="外观设计">外观设计</option>
                                        <option value="软件登记">软件登记</option>
                                    </select>
                                </div>
                                <div class="form-group">
                                    <label for="query-postName">公司专利奖励</label>
                                    <input id="query-postName" type="text" name="reward" class="form-control"
                                           placeholder="请输入公司专利奖励">
                                </div>
                                <div class="form-group">
                                    <label for="query-patentCode">专利编码</label>
                                    <input id="query-patentCode" type="text" name="patentCode" class="form-control"
                                           placeholder="请输入专利编码">
                                </div>
                                <div class="form-group">
                                    <label for="query-projectRemark">涉及项目</label>
                                    <input id="query-projectRemark" type="text" name="projectRemark" class="form-control"
                                           placeholder="请输入涉及项目">
                                </div>
                                <div class="form-group">
                                    <label for="query-deptName">设计所</label>
                                    <input id="query-deptName" type="text" name="deptName" class="form-control"
                                           placeholder="请输入设计所">
                                </div>
                                <div class="form-group">
                                    <label for="query-field">专业领域</label>
                                    <input id="query-field" type="text" name="field" class="form-control"
                                           placeholder="请输入专业领域">
                                </div>
                                <div class="form-group">
                                    <label for="query-status">状态</label>
                                    <select id="query-status" class="form-control" name="status">
                                        <option value="" selected>请选择</option>
                                        <option value="1">未申报</option>
                                        <option value="2">已申报</option>
                                        <option value="3">等待受理</option>
                                        <option value="4">已受理</option>
                                        <option value="5">授权</option>
                                        <option value="6">退回</option>
                                    </select>
                                </div>
                                <button type="button" class="btn btn-success" id="btn-search"
                                        onclick="js.table.search(table)">
                                    <span class="Bold">搜索</span>
                                </button>
                            </div>
                        </div>
                    </form>
                    <button type="button" style="min-width: 92px" class="btn btn-success pull-right" id="btn-receive" shiro:hasPermission="sat:invention:edit"
                            onclick="openReleaseModal()" >
                        <span class="Bold">新增</span>
                    </button>
                </div>
                <div class="box-body">
                    <table id="bootstrap-table" style="width: 99.9%;font-size:12px;"></table>
                </div>
            </div>
        </div>
    </div>
</section>
<!-- 模态框（Modal） -->
<div class="modal fade" id="myModalAdd" role="dialog" aria-labelledby="myModalLabel" aria-hidden="true">
    <div class="modal-dialog">
        <div class="modal-content">
            <div class="modal-header">
                <button type="button" class="close" data-dismiss="modal"
                        aria-hidden="true">×
                </button>
                <h4 class="modal-title" id="partFormAdd-myModalLabel" align="center">
                    新增发明专利信息
                </h4>
            </div>
            <div class="modal-body">
                <form id="partFormAdd" class="form-horizontal" role="form">
                    <input type="hidden" id="partFormAdd-id" name="id">
                    <div class="form-group" id="partFormAdd-DD">
                        <label class="col-sm-3 control-label no-padding-right">发明专利名称 ：</label>
                        <div class="col-sm-9">
                            <input class="form-control" name="name" id="partFormAdd-name">
                        </div>
                    </div>
                    <div class="form-group" id="KK">
                        <label class="col-sm-3 control-label no-padding-right">申请类型 ：</label>
                        <div class="col-sm-9">
                            <select class="form-control" name="typeName">
                                <option value="" selected="selected">请选择</option>
                                <option value="发明">发明</option>
                                <option value="实用新型">实用新型</option>
                                <option value="外观设计">外观设计</option>
                                <option value="软件登记">软件登记</option>
                            </select>
                        </div>
                    </div>
                    <div class="form-group">
                        <label class="col-sm-3 control-label no-padding-right">发明人 ：</label>
                        <div class="col-sm-9">
                            <input type="text" class="form-control" name="inventor" id="partFormAdd-inventor">
                        </div>
                    </div>
                    <div class="form-group">
                        <label class="col-sm-3 control-label no-padding-right">提报时间 ：</label>
                        <div class="col-sm-9">
                            <input type="text" class="form-control datepicker" name="applyTime"
                                   readonly="readonly" style="width: 100%;"/>
                        </div>
                    </div>
                    <div class="form-group">
                        <label class="col-sm-3 control-label no-padding-right">受理时间 ：</label>
                        <div class="col-sm-9">
                            <input type="text" class="form-control datepicker" name="acceptanceTime"
                                   readonly="readonly" style="width: 100%;"/>
                        </div>
                    </div>
                    <div class="form-group">
                        <label class="col-sm-3 control-label no-padding-right">授权时间 ：</label>
                        <div class="col-sm-9">
                            <input type="text" class="form-control datepicker" name="authorizedTime"
                                   readonly="readonly" style="width: 100%;"/>
                        </div>
                    </div>
                    <div class="form-group">
                        <label class="col-sm-3 control-label no-padding-right">专利编码 ：</label>
                        <div class="col-sm-9">
                            <input type="text" class="form-control" name="patentCode"
                                   id="partFormAdd-patentCode">
                        </div>
                    </div>
                    <div class="form-group">
                        <label class="col-sm-3 control-label no-padding-right">公司专利奖励 ：</label>
                        <div class="col-sm-9">
                            <input type="text" class="form-control" name="reward"
                                   id="partFormAdd-reward">
                        </div>
                    </div>
                    <div class="form-group">
                        <label class="col-sm-3 control-label no-padding-right">状态 ：</label>
                        <div class="col-sm-9">
                            <select class="form-control" name="status">
                                <option value="" selected>请选择</option>
                                <option value="1">未申报</option>
                                <option value="2">已申报</option>
                                <option value="3">等待受理</option>
                                <option value="4">已受理</option>
                                <option value="5">授权</option>
                                <option value="6">退回</option>
                            </select>
                        </div>
                    </div>
                    <div class="form-group">
                        <label class="col-sm-3 control-label no-padding-right">设计所 ：</label>
                        <div class="col-sm-9">
                            <input class="form-control" name="deptName"  type="text">
                        </div>
                    </div>
                    <div class="form-group">
                        <label class="col-sm-3 control-label no-padding-right">专业领域 ：</label>
                        <div class="col-sm-9">
                            <input class="form-control" type="text" name="field">
                        </div>
                    </div>
                    <div class="form-group">
                        <label class="col-sm-3 control-label no-padding-right">涉及项目 ：</label>
                        <div class="col-sm-9">
                            <textarea name="projectRemark" rows="3" style="width: 100%;"></textarea>
                        </div>
                    </div>
                </form>
            </div>
            <div class="modal-footer">
                <button type="button" class="btn btn-default"
                        data-dismiss="modal">关闭
                </button>
                <button type="button" class="btn btn-primary" onclick="saveMaintain()" id="partFormAddbtn-add"
                       >
                    添加
                </button>
            </div>
        </div><!-- /.modal-content -->
    </div><!-- /.modal-dialog -->
</div><!-- /.modal -->
<!--!-- 模态框（Modal） -->
<div class="modal fade" id="myModalEdit" role="dialog" aria-labelledby="myModalLabel" aria-hidden="true">
    <div class="modal-dialog">
        <div class="modal-content">
            <div class="modal-header">
                <button type="button" class="close" data-dismiss="modal"
                        aria-hidden="true">×
                </button>
                <h4 class="modal-title" id="myModalLabel" align="center">
                    维护发明专利信息
                </h4>
            </div>
            <div class="modal-body">
                <form id="partForm" class="form-horizontal" role="form">
                    <input type="hidden" id="id" name="id">
                    <div class="form-group">
                        <label class="col-sm-3 control-label no-padding-right">发明专利名称 ：</label>
                        <div class="col-sm-9">
                            <input class="form-control" name="name" id="partForm-name">
                        </div>
                    </div>
                    <div class="form-group">
                        <label class="col-sm-3 control-label no-padding-right">申请类型 ：</label>
                        <div class="col-sm-9">
                            <select class="form-control" name="typeName">
                                <option value="" selected="selected">请选择</option>
                                <option value="发明">发明</option>
                                <option value="实用新型">实用新型</option>
                                <option value="外观设计">外观设计</option>
                                <option value="软件登记">软件登记</option>
                            </select>
                        </div>
                    </div>
                    <div class="form-group">
                        <label class="col-sm-3 control-label no-padding-right">发明人 ：</label>
                        <div class="col-sm-9">
                            <input type="text" class="form-control" name="inventor" id="partForm-inventor">
                        </div>
                    </div>
                    <div class="form-group">
                        <label class="col-sm-3 control-label no-padding-right">提报时间 ：</label>
                        <div class="col-sm-9">
                            <input type="text" class="form-control datepicker" name="applyTime"
                                   readonly="readonly" style="width: 100%;"/>
                        </div>
                    </div>
                    <div class="form-group">
                        <label class="col-sm-3 control-label no-padding-right">受理时间 ：</label>
                        <div class="col-sm-9">
                            <input type="text" class="form-control datepicker" name="acceptanceTime"
                                   readonly="readonly" style="width: 100%;"/>
                        </div>
                    </div>
                    <div class="form-group">
                        <label class="col-sm-3 control-label no-padding-right">授权时间 ：</label>
                        <div class="col-sm-9">
                            <input type="text" class="form-control datepicker" name="authorizedTime"
                                   readonly="readonly" style="width: 100%;"/>
                        </div>
                    </div>
                    <div class="form-group">
                        <label class="col-sm-3 control-label no-padding-right">专利编码 ：</label>
                        <div class="col-sm-9">
                            <input type="text" class="form-control" name="patentCode"
                                   id="partForm-patentCode">
                        </div>
                    </div>
                    <div class="form-group">
                        <label class="col-sm-3 control-label no-padding-right">公司专利奖励 ：</label>
                        <div class="col-sm-9">
                            <input type="text" class="form-control" name="reward"
                                   id="partForm-reward">
                        </div>
                    </div>
                    <div class="form-group">
                        <label class="col-sm-3 control-label no-padding-right">状态 ：</label>
                        <div class="col-sm-9">
                            <select class="form-control" name="status">
                                <option value="" selected>请选择</option>
                                <option value="1">未申报</option>
                                <option value="2">已申报</option>
                                <option value="3">等待受理</option>
                                <option value="4">已受理</option>
                                <option value="5">授权</option>
                                <option value="6">退回</option>
                            </select>
                        </div>
                    </div>
                    <div class="form-group">
                        <label class="col-sm-3 control-label no-padding-right">设计所 ：</label>
                        <div class="col-sm-9">
                            <input class="form-control" name="deptName" id="partForm-deptName" type="text">
                        </div>
                    </div>
                    <div class="form-group">
                        <label class="col-sm-3 control-label no-padding-right">专业领域 ：</label>
                        <div class="col-sm-9">
                            <input class="form-control" type="text" name="field">
                        </div>
                    </div>
                    <div class="form-group">
                        <label class="col-sm-3 control-label no-padding-right">涉及项目 ：</label>
                        <div class="col-sm-9">
                            <textarea name="projectRemark" rows="3" style="width: 100%;"></textarea>
                        </div>
                    </div>
                </form>
            </div>
            <div class="modal-footer">
                <button type="button" class="btn btn-default"
                        data-dismiss="modal">关闭
                </button>
                <button type="button" class="btn btn-primary" onclick="editMaintain()" id="btn-edit"
                        >
                    编辑
                </button>
            </div>
        </div><!-- /.modal-content -->
    </div><!-- /.modal-dialog -->
</div>
<!--上传附件-->
<div class="modal fade" data-backdrop="static" data-keyboard="false" id="modal-upload">
    <div class="modal-dialog">
        <div class="modal-content">
            <div class="modal-header">
                <button type="button" class="close" data-dismiss="modal" aria-label="Close">
                    <span aria-hidden="true">&times;</span></button>
                <h4 class="modal-title">上传附件</h4>
            </div>
            <div class="modal-body">
                <form id="uploadForm">
                    <input id="uploadForm-id" name="id" type="hidden">
                    <div class="form-group">
                        <label>选择附件上传</label>
                        <input class="btn" type="file" name="file">
                        <p class="help-block">多个文件请自行打包上传，大小不要超过100M</p>
                        <p class="help-block text-red">单条专利附件不支持上传同名文件</p>
                    </div>
                </form>
            </div>
            <div class="modal-footer">
                <button  id="btn-upload" type="button"
                        class="btn btn-success">
                    <span class="Bold">上传</span>
                </button>
                <button type="button" class="btn btn-default" data-dismiss="modal">取消</button>
            </div>
        </div>
    </div>
</div>
<div th:include="include :: footer"></div>
<script th:inline="javascript">

    let table;
    var statusNames = ["", "未申报", "已申报", "等待受理", "已受理", "授权", "退回"];

    /** * 新增打开模态框 */
    function openReleaseModal() {
        document.getElementById("partFormAdd").reset();
        js.modal.open("myModalAdd");

    }

    /*修改打开模态框*/
    function updateProduction(result) {
        $("#partForm").fillData(result);
        js.modal.open("myModalEdit");
    }

    /**保存-模态框*/
    function saveMaintain() {
        // let res = js.vd({
        //     id: 'partFormAdd',
        //     notEmpty: ['name', 'typeName', 'inventor', 'status']
        // })
        // if (!res) {
        //     return;
        // }
        var url = ctx + "invention/save";
        js.validSubmit({
            formId: "partFormAdd",
            url: url,
            data: new FormData($("#partFormAdd")[0]),
            success: function (result) {
                if (result.type === web_status.SUCCESS) {
                    js.modal.success(result.msg);
                    js.table.refresh(table);
                    js.modal.hide("myModalAdd");
                } else {
                    js.modal.warning(result.msg);
                }
            }
        });

    }

    /**维护模态框*/
    function editMaintain() {
        // let res = js.vd({
        //     id: 'partForm',
        //     notEmpty: ['name', 'typeName', 'inventor', 'status']
        // })
        // if (!res) {
        //     return;
        // }
        var url = ctx + "invention/edit";
        js.validSubmit({
            formId: "partForm",
            url: url,
            data: new FormData($("#partForm")[0]),
            success: function (result) {
                if (result.type === web_status.SUCCESS) {
                    js.modal.success(result.msg);
                    js.table.refresh(table);
                    js.modal.hide("myModalEdit");
                } else {
                    js.modal.warning(result.msg);
                }
            }
        });

    }

    /** 删除数据 */
    function del(id) {
        js.modal.confirm("确认删除吗？", function () {
            js.post({
                url: ctx + "invention/del",
                data: {id: id},
                success: function (result) {
                    if (result.type === web_status.SUCCESS) {
                        js.modal.success(result.msg);
                        js.table.refresh(table);
                    } else {
                        js.modal.warning(result.msg);
                    }
                }
            })
        })
    }

    /**打开上传附件模态框*/
    function upload(id) {
        $("#uploadForm-id").val(id);
        js.modal.open('modal-upload');
    };
    /** 上传附件 */
    $("#btn-upload").click(function () {
        var $this = $(this);
        $this.attr('disabled', true);
        js.validSubmit({
            formId: "uploadForm",
            url: ctx + "invention/upload",
            data: new FormData($("#uploadForm")[0]),
            success: function (result) {
                if (result.type === web_status.SUCCESS) {
                    js.modal.success(result.msg);
                    js.modal.hide("modal-upload");
                    js.table.refresh(table);
                } else {
                    js.modal.warning(result.msg);
                }
            }
        });
        $this.attr('disabled', false);
    });
    $(function () {

        /** 设计进度列表 */
        table = js.table.init({
            url: ctx + "invention/query",
            showExport: true,
            columns: [
                {

                    title: '序号', field: 'id', width: '50',
                    formatter: function (value, row, index) {
                        return index + 1;
                    }
                },
                {title: "发明专利名称", field: 'name', width: '120'},
                {title: "申请类型", field: 'typeName'},
                {title: "发明人", field: 'inventor', width: '180'},
                {title: "提报时间", field: 'applyTime',width:'90'},
                {title: "受理时间", field: 'acceptanceTime',width:'90'},
                {title: "授权时间", field: 'authorizedTime',width:'90'},
                {title: "专利编码", field: 'patentCode'},
                {title: "公司专利<br>奖励", field: 'reward',width:'50'},
                {
                    title: "状态", field: 'status',width:'80',
                    formatter: function (value) {
                        return statusNames[value];
                    }
                },
                {
                    title: "附件", field: 'certificateNo',
                    formatter: function (value) {
                        if (value) {
                            return '<a target="_blank" href="' + value + '">下载</a>'
                        }
                        return value;
                    }
                },
                {title: "设计所", field: 'deptName',width:'100'},
                {title: "专业领域", field: 'field',width:'100'},
                {title: "涉及项目", field: 'projectRemark',width:'150'},
                {
                    title: "操作",width:'110',
                    formatter: function (value, row) {
                        let actions = [];
                        if (hasP('sat:invention:edit') ) {
                        actions.push('<a class="btn btn-warning btn-xs"  onclick="updateProduction(' + js.jsonStringify(row) + ')"> 编辑</a> ');
                        actions.push('<a class="btn btn-danger btn-xs"  onclick="del(' + row.id + ')" > 删除</a> ');
                        actions.push('<a class="btn btn-info btn-xs"  onclick="upload(' + row.id + ')" > 上传附件</a> ');
                        }
                        return actions.join('');
                    }
                }
            ]
        });
        // /** 重置表单及验证 */
        // js.modal.hideEvent("modal-upload", function () {
        //     js.validate.reset("uploadForm");
        //     js.reset("uploadForm");
        // })
        /** 重置表单及验证 */
        js.modal.hideEvent("myModaledit", function () {
            js.validate.reset("partForm");
            js.reset("partForm");
        })
    });

</script>
</body>
</html>
